package javademo;

public class DeadLockDemo {
    private static Object obj1 = new Object();
    private static Object obj2 = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (obj1) {
                try {
                    System.out.println("11-----------");
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (obj2) {
                    System.out.println("12-----------");
                }
            }
        }).start();
        new Thread(() -> {
            synchronized (obj2) {
                try {
                    System.out.println("21-----------");
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (obj1) {
                    System.out.println("22-----------");
                }
            }
        }).start();
    }
}
